package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IStatusOfRequestDAO;
import com.AAL.Model.StatusOfRequest;
import com.AAL.Utils.HibernateUtil;

public class StatusOfRequestDAO implements IStatusOfRequestDAO{

	@Override
	public StatusOfRequest getStatusOfRequest(int statusID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StatusOfRequest statusOfRequest = (StatusOfRequest) session.load(StatusOfRequest.class,(short) statusID);
		return statusOfRequest;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<StatusOfRequest> getAllStatusOfRequests() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<StatusOfRequest> lstStatusOfRequests = null;
		try {
			lstStatusOfRequests = (List<StatusOfRequest>) session.createQuery(
					"from StatusOfRequest").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstStatusOfRequests;
	}

}
